package guru.merlin.bus.demo;



import guru.merlin.bus.EnvelopeBus;
import guru.merlin.bus.MessagingInfrastructureException;
import guru.merlin.core.CantHandException;
import guru.merlin.core.Envelope;
import guru.merlin.core.EnvelopeHandler;
import guru.merlin.core.Route;

import java.util.Map;


class Consumidor implements EnvelopeHandler{

	public static void main(String argv[]){
	    try{
	        System.out.println("Consumidor arriba");
	        EnvelopeBus bus=new EnvelopeBus();
	        Consumidor c=new Consumidor();
	        Route r=Proveedor.RUTA;
	        bus.connectHandler(c,r);
	        
	        System.out.println("Consumidor corriendo");
	        bus.start();
	    }
		catch(MessagingInfrastructureException e){
		    System.err.println("Problemas con la infraestructura de mensajera, favor revise el servicio.");
		}

	    catch(Exception e){
		    e.printStackTrace();
	    }

	}


    public Object handEnvelope(Envelope envelope) throws CantHandException {
		System.out.println("=Mensaje recibido!=>"+envelope.toString());
		return envelope;
    }

    public void handEnvelopes(Map envelopes) {
        
    }


    /* (sin Javadoc)
     * @see guru.merlin.core.EnvelopeHandler#retrieveEnvelope(java.lang.Object)
     */
    public void retrieveEnvelope(Object EnvelopeReference) throws CantHandException {
    }


    /* (sin Javadoc)
     * @see guru.merlin.core.EnvelopeHandler#commitHandEnvelope(java.lang.Object)
     */
    public void commitHandEnvelope(Object EnvelopeReference) throws CantHandException {
    }
}